using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Validation.Configuration.Design.ValidatorNodes;
using EntLibContrib.Validation.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Validation.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Configuration.Design.Validation;
using System.ComponentModel;
using Microsoft.Practices.EnterpriseLibrary.Configuration.Design;
using System.Drawing.Design;

namespace EntLibContrib.Validation.Design.Nodes
{
    public class ExternallyConfiguredObjectValidatorNode : SingleValidatorNodeBase
    {
        private string targetRuleset;
        private string targetConfigurationFile;

        public ExternallyConfiguredObjectValidatorNode()
            : this(new ExternallyConfiguredObjectValidatorData(Resources.ExternallyConfiguredObjectValidatorNodeName))
        {
        }

        public ExternallyConfiguredObjectValidatorNode(ExternallyConfiguredObjectValidatorData validatorData)
            : base(validatorData)
        {
            targetRuleset = validatorData.TargetRuleset;
            targetConfigurationFile = validatorData.TargetConfigurationFile;
        }

        [Required]
        [SRCategory("CategoryGeneral", typeof(Resources))]
        [SRDescription("DescriptionTargetConfigurationFile", typeof(Resources))]
        [Editor(typeof(OpenFileEditor), typeof(UITypeEditor))]
        [FilteredFileNameEditor(typeof(Resources), "ConfigurationFileDialogFilter")]
        [FileValidationAttribute]	
        public string TargetConfigurationFile
        {
            get { return targetConfigurationFile; }
            set { targetConfigurationFile = value; }
        }

        [SRCategory("CategoryGeneral", typeof(Resources))]
        [SRDescription("DescriptionTargetRuleSet", typeof(Resources))]
        public string TargetRuleSet
        {
            get { return targetRuleset; }
            set { targetRuleset = value; }
        }

        public override ValidatorData CreateValidatorData()
        {
            ExternallyConfiguredObjectValidatorData validatorData = new ExternallyConfiguredObjectValidatorData(Name);
            base.SetValidatorBaseProperties(validatorData);

            validatorData.TargetConfigurationFile = targetConfigurationFile;
            validatorData.TargetRuleset = targetRuleset;

            return validatorData;
        }

    }
}
